package com.tj.pystandard.tjapi.common.util;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;

import java.util.concurrent.TimeUnit;

/**
 * Redis工具类
 *
 * @author qiuting
 * @date 2020/11/5 12:00
 */
@Slf4j
public class RedisUtil {
	private static Gson gson = new GsonBuilder().create();

	public static Object getValue(RedisTemplate redisTemplate, Object key) {
		return redisTemplate.opsForValue().get(key);
	}

	public static void setValue(RedisTemplate redisTemplate, Object key, Object value, int i, TimeUnit timeUnit) {
		redisTemplate.opsForValue().set(key, value, i, timeUnit);
	}

	public static String getRedisKey(Object vo, String dir) {
		return dir + ":" + gson.toJson(vo).replace(":", "=");
	}
}
